﻿namespace OpenPms.Controllers;
/// <summary>
/// 房间
/// </summary>
[Route("api/[controller]")]
public class RoomController : PmsControllerBase<RoomController>
{
    public RoomController(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }
    ///// <summary>
    ///// 错误代码
    ///// </summary>
    ///// <returns></returns>
    //[HttpGet(nameof(ErrorCodes))]
    //public ResponseError ErrorCodes()
    //{
    //    return new();

    //}

    /// <summary>
    /// 获取房型房间信息
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public async Task<List<VRoomType>> Rooms()
    {

        return await db.RoomTypes.Include(ii => ii.Rooms).Where(ii => ii.HotelId == HotelId).Select(ii => new VRoomType { Id = ii.Id, Name = ii.Name, Rooms = ii.Rooms.Select(jj => new VRoom() { RoomNo = jj.RoomNo, Desc = jj.Desc }).ToList() }).ToListAsync();

    }

    /// <summary>
    /// 获取可用房间
    /// </summary>
    /// <param name="roomTypeId">房间类型，如"59014996-5380-4B7A-96DE-0440DED13512"</param>
    /// <param name="quantity">房间数量</param>
    /// <returns></returns>
    [HttpGet(nameof(AvailableRoom) + "/{roomTypeId}/{quantity}")]
    public Task<List<VRoom>> AvailableRoom(Guid roomTypeId, int quantity = 1) =>
        OrderService.GetAvailableRoomsAsync(HotelId, roomTypeId, quantity);
    /// <summary>
    /// 查询房间状态
    /// </summary>
    /// <param name="roomNo"></param>
    /// <returns></returns>
    [HttpGet(nameof(QueryRoomStatus) + "/{roomNo}")]
    public async Task<VRoom> QueryRoomStatus(string roomNo)
    {
        return await OrderService.QueryRoomStatusAsync(HotelId, roomNo);
    }
    ///// <summary>
    ///// 排房
    ///// </summary>
    ///// <param name="q"></param>
    ///// <returns></returns>
    //[HttpPost(nameof(ArrangeRoom))]
    //public Task<bool> ArrangeRoom(RequestArrangeRoom q)
    //{
    //    q.HotelId = HotelId;
    //    q.UserId = ApiUserId;
    //    return OrderService.ArrangeRoomAsync(q);
    //}
    ///// <summary>
    ///// 获取来源信息
    ///// </summary>
    ///// <returns></returns>
    //[HttpGet(nameof(Sources))]
    //public List<SourceItem> Sources([FromServices] IConfiguration configuration) =>
    //    configuration.GetSection(SourceItem.SetctionName).Get<List<SourceItem>>()!;

    ///// <summary>
    ///// 获取价格码信息
    ///// </summary>
    ///// <returns></returns>
    //[HttpGet(nameof(Rates))]
    //public async Task<List<TRate>> Rates([FromServices] Data.AppDbContext db)
    //{
    //    return await db.Rates.Where(ii => ii.HotelId == HotelId && ii.IsPublish).ToListAsync();
    //}
    /// <summary>
    /// 查询房价房量
    /// </summary>
    /// <param name="rateId">房价码</param>
    /// <param name="dateStart">开始日期</param>
    /// <param name="dateEnd">结束日期，包含该日期</param>
    /// <param name="roomTypeId">房型代码，可空，若为空则返回全部房型的数据</param>
    /// <returns></returns>
    [HttpGet("PriceAndQuantity")]
    public Task<List<VPriceQuantity>> PriceAndQuantity(Guid rateId, DateOnly dateStart, DateOnly dateEnd, Guid? roomTypeId = null)
        => OrderService.QueryPriceQuantityAsync(HotelId, rateId, dateStart, dateEnd, roomTypeId);

    ///// <summary>
    ///// 新增订单
    ///// </summary>
    ///// <param name="q"></param>
    ///// <returns>订单号</returns>
    //[HttpPost(nameof(CreateOrder))]
    //public async Task<Guid> CreateOrder(RequestCreateOrder q)
    //{
    //    q.HotelId = HotelId;
    //    q.ApiName = ApiName;
    //    return await OrderService.CreateOrderAsync(q);
    //}

    ///// <summary>
    ///// 取消订单
    ///// </summary>
    ///// <param name="q"></param>
    ///// <returns>主订单号</returns>
    //[HttpPost(nameof(CancelOrder))]
    //public async Task<Guid> CancelOrder(RequestCancelOrder q)
    //{
    //    q.HotelId = HotelId;
    //    q.ApiName = ApiName;
    //    return await OrderService.CancelOrderAsync(q);
    //}

    ///// <summary>
    ///// 查询预订单
    ///// </summary>
    ///// <param name="q"></param>
    ///// <returns></returns>

    //[HttpPost(nameof(QueryReservation))]
    //public async Task<List<VOrder>> QueryReservation(RequestQueryReservation q)
    //{
    //    q.HotelId = HotelId;
    //    return await OrderService.QueryReservationAsync(q);
    //}
    ///// <summary>
    ///// 拆分预订单，并自动排房
    ///// </summary>
    ///// <param name="orderId">订单号</param>
    ///// <returns>拆分后的订单号列表</returns>
    //[HttpPost(nameof(SplitReservation))]
    //public Task<List<VRoom>> SplitReservation(Guid orderId)
    //{
    //    return OrderService.SplitReservationAsync(HotelId, orderId, ApiName);
    //}


}
